home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / gdm / guest-session / guest-session-cleanup.sh next >
Linux/UNIX/POSIX Shell Script  |  2009-10-15  |  890b  |  40 lines

  1. #!/bin/sh -e
  2. # (C) 2008 Canonical Ltd.
  3. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  4. # License: GPL v2 or later
  5. #
  6. # Clean up user and temporary home directory for guest session.
  7. # Requires guest account name as $1.
  8.  
  9. USER="$1"
  10.  
  11. PWENT=`getent passwd "$USER"` || {
  12.     echo "Error: invalid user $USER"
  13.     exit 1
  14. }
  15. UID=`echo "$PWENT" | cut -f3 -d:`
  16. HOME=`echo "$PWENT" | cut -f6 -d:`
  17.  
  18. if [ "$UID" -ge 500 ]; then
  19.     echo "Error: user $USER is not a system user."
  20.     exit 1
  21. fi
  22.  
  23. # kill all remaining processes
  24. while ps h -u "$USER" >/dev/null; do 
  25.     killall -9 -u "$USER" || true
  26.     sleep 0.2; 
  27. done
  28.  
  29. umount "$HOME" || umount -l "$HOME" || true
  30. rm -rf "$HOME"
  31.  
  32. # remove leftovers in /tmp
  33. find /tmp -mindepth 1 -maxdepth 1 -uid "$UID" | xargs rm -rf || true
  34.  
  35. # remove gdm cache files
  36. find /var/cache/gdm -mindepth 1 -maxdepth 1 -uid "$UID" | xargs rm -rf || true
  37.  
  38. deluser --system "$USER"
  39.  
  40.